package cn.com.header.core.support.security.spring;

import cn.com.header.core.support.web.JsonViewData;
import cn.com.header.core.support.web.ResultCode;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 验证成功之后返回JSON串
 * <pre>
 *     {"resultCode":"SUCCESS","message":"登录成功。"}
 * </pre>
 * @author Liangzhongqiu
 * @date 2017/8/31 031
 * @time 20:50
 */
public class AjaxLoginSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        new JsonViewData(ResultCode.SUCCESS,"登录成功。").write(response);
    }
}
